import { TableColumnCtx } from 'element-plus'
import { VNode } from 'vue'
import {
  LockStatus,
  OnlineStatus,
  BizType,
  PaymentType,
  UserStatusType,
  RefundState,
  CanUseCoupon,
  AllowChangeBattery,
  PayAfterUse,
  isHasMask,
  isHasBattery,
  MaskStatusType,
  LuggageStatus,
  depositDeductionOperationType,
  workOrderStatus,
  GenderType,
  ChannelType
} from '@/types/enum'
type TableFormatterType = VNode | string

export const lockStatus = (row: any, column?: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case LockStatus.Locked:
      return '上锁'
    case LockStatus.Unlocked:
      return '开锁'
    default:
      return ''
  }
}
export const bikeOnlineStatus = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case OnlineStatus.UnOnLine:
      return '断网'
    case OnlineStatus.OnLine:
      return '联网'
    default:
      return ''
  }
}
export const bizType = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case BizType.ChangeBattery:
      return '换电套餐-不含电'
    case BizType.BatteryTimesCard:
      return '电池次卡-不含电'
    case BizType.BatteryOverdue:
      return '电池逾期'
    case BizType.BatteryActivity:
      return '电池套餐-含电'
    case BizType.BatteryOverdueRerent:
      return '电池逾期续租-组合支付'
    case BizType.BatteryDeposit:
      return '电池押金退款'
    case BizType.BatteryRerent:
      return '电池续租'
    case BizType.BikeLongTerm:
      return '车辆长租'
    case BizType.BikeShortTerm:
      return '车辆短租'
    case BizType.BikeOverdue:
      return '租车逾期'
    case BizType.BikeRerent:
      return '租车续租'
    case BizType.BikeOverdueRerent:
      return '租车逾期续租'
    case BizType.BikeDeposit:
      return '租车押金退款'
    case BizType.OnlineBike:
      return '车辆售卖'
    case BizType.BikeModified:
      return '中控线材电池'
    case BizType.Battery:
      return '电池购买'
    case BizType.BatterySwap:
      return '单次换电'
    case BizType.AdditionalFees:
      return '其他收费'
    case BizType.BalanceRecharge:
      return '余额充值'
    case BizType.BalanceWithdraw:
      return '余额提现'
    case BizType.BikeDepositCard:
      return '押金卡'
    case BizType.BikeDepositCardRefund:
      return '押金卡退款'
    case BizType.BikeMarginRefund:
      return '出区域保证金退款'
    case BizType.BikeMargin:
      return '出区域保证金'
    case BizType.BikeRentCard:
      return '骑行卡'
    default:
      return '其他'
  }
}
export const paymentType = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case PaymentType.Alipay:
      return '支付宝'
    case PaymentType.WeChat:
      return '微信'
    default:
      return ''
  }
}
export const longbikestate = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case '1':
      return '空闲'
    case '0':
      return '全部'
    case '2':
      return '断网'
    case '3':
      return '租赁中'
    default:
      return '其他'
  }
}
export const useStatus = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case UserStatusType.Nomal:
      return '正常'
    case UserStatusType.Fozen:
      return '冻结中'
    default:
      return '其他'
  }
}
export const refundState = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case RefundState.UnderReview:
      return '审核中'
    case RefundState.Refund:
      return '退款中'
    case RefundState.Refunded:
      return '已退款'
    case RefundState.OverRule:
      return '被驳回'
    case RefundState.WithDraw:
      return '已撤回'
    default:
      return '其他'
  }
}
export const allowChangeBattery = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case AllowChangeBattery.Allow:
      return '支持'
    case AllowChangeBattery.UnAllow:
      return '不支持'
    default:
      return ''
  }
}
export const payAfterUse = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case PayAfterUse.Allow:
      return '支持'
    case PayAfterUse.UnAllow:
      return '不支持'
    default:
      return ''
  }
}
export const canUseCoupon = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data = column ? row[column.property] : row
  switch (data) {
    case CanUseCoupon.Allow:
      return '支持'
    case CanUseCoupon.UnAllow:
      return '不支持'
    default:
      return ''
  }
}
export const formatterIsHasMask = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: isHasMask = column ? row[column.property] : row
  switch (data) {
    case '0':
      return '否'
    case '1':
      return '是'
    default:
      return ''
  }
}
export const formatterIsHasBattery = (
  row: any,
  column: TableColumnCtx<any>
): TableFormatterType => {
  const data: isHasBattery = column ? row[column.property] : row
  switch (data) {
    case '0':
      return '无电池'
    case '1':
      return '有电池'
    default:
      return ''
  }
}
export const formatterMaskStatus = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: MaskStatusType = column ? row[column.property] : row
  switch (data) {
    case '0':
      return '头盔已归还'
    case '1':
      return '头盔未归还'
    default:
      return ''
  }
}
export const formatterLuggageStatus = (
  row: any,
  column: TableColumnCtx<any>
): TableFormatterType => {
  const data: LuggageStatus = column ? row[column.property] : row
  switch (data) {
    case '0':
      return '池仓关闭'
    case '1':
      return '池仓开启'
    default:
      return ''
  }
}
export const formatterDepositDeductionOperationType = (
  row: any,
  column: TableColumnCtx<any>
): TableFormatterType => {
  const data: depositDeductionOperationType = column ? row[column.property] : row
  switch (data) {
    case '0':
      return '违章费'
    case '1':
      return '维修费'
    case '2':
      return '逾期费'
    case '3':
      return '赔偿费'
    default:
      return '其他费用类型'
  }
}
export const formatterRole = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: 'customer' | 'admin' = column ? row[column.property] : row
  switch (data) {
    case 'customer':
      return '客服'
    case 'admin':
      return '管理员'
  }
}
export const formatGender = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: GenderType = column ? row[column.property] : row
  switch (data) {
    case 0:
      return '未知'
    case 1:
      return '男'
    case 2:
      return '女'
    default:
      return '未知'
  }
}
export const formatterPower = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: string | number = column ? row[column.property] : row
  return data ? data.toString() + '%' : '0%'
}

export const formatterWorkOrderStatus = (
  row: any,
  column: TableColumnCtx<any>
): TableFormatterType => {
  const data: workOrderStatus = column ? row[column.property] : row
  switch (data) {
    case 'PENDING':
      return '待处理'
    case 'CANCELLED':
      return '已取消'
    case 'COMPLETED':
      return '已完成'
    case 'IN_PROGRESS':
      return '已接单'
    case 'REVIEWING':
      return '待审核'
    default:
      return ''
  }
}

export const formatChannel = (row: any, column: TableColumnCtx<any>): TableFormatterType => {
  const data: ChannelType = column ? row[column.property] : row
  switch (data) {
    case 'IOS':
      return '苹果'
    case 'Android':
      return '安卓'
    case 'WeChat':
      return '小程序'
    default:
      return ''
  }
}
